package co.edu.usbcali.raju.core.graphics;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.GroupLayout;
import javax.swing.JTextArea;
import javax.swing.GroupLayout.Alignment;
import javax.swing.GroupLayout.ParallelGroup;
import javax.swing.GroupLayout.SequentialGroup;
import javax.swing.JButton;

public class RajuChess {
	public static final int SIZE=8;

	private JFrame frame;
	private JButton[][] board=new JButton[SIZE][SIZE];

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					RajuChess window = new RajuChess();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public RajuChess() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 450, 300);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		for(int row=0;row<board.length;row++){
			for(int col=0;col<board[0].length;col++){
				board[row][col]=new JButton();
			}
			
		}
		JTextArea jTextArea = new JTextArea();
		GroupLayout groupLayout = new GroupLayout(frame.getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createSequentialGroup()
			.addGroup(createButtonBoardParSeq(groupLayout))
			.addComponent(jTextArea));
		
			/*
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(26)
					.addComponent(btnNewButton)
					.addContainerGap(305, Short.MAX_VALUE))
					
		);
		*/
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
			.addGroup(createButtonBoardSeqPar(groupLayout)
					)
			.addComponent(jTextArea));
			/*
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(26)
					.addComponent(btnNewButton)
					.addContainerGap(221, Short.MAX_V, groupLayout)groupLayout.createPSequentialGroup()
					.addGroup(createButtonFilePar(0, groupLayout))
					.addGroup(createButtonFilePar(1, groupLayout))
					.addGroup(createButtonFilePar(2, groupLayout))
					.addGroup(createButtonFilePar(3, groupLayout))
					.addGroup(createButtonFilePar(4, groupLayout))
					.addGroup(createButtonFilePar(5, groupLayout))
					.addGroup(createButtonFilePar(6, groupLayout))
					.addGroup(createButtonFilePar(7, groupALUE))
		);
		*/
		frame.getContentPane().setLayout(groupLayout);
	}
	
	public SequentialGroup createButtonFileSeq(int n,GroupLayout groupLayout){
		SequentialGroup sequentialGroup=groupLayout.createSequentialGroup();
		for(int i=0;i<SIZE;i++){
			sequentialGroup.addComponent(board[n][i]);
		}
		return sequentialGroup;		
	}

	public ParallelGroup createButtonFilePar(int n,GroupLayout groupLayout){
		ParallelGroup parallelGroup=groupLayout.createParallelGroup();
		for(int i=0;i<SIZE;i++){
			parallelGroup.addComponent(board[n][i]);
		}
		return parallelGroup;		
	}

	public SequentialGroup createButtonBoardSeqPar(GroupLayout groupLayout){
		SequentialGroup sequentialGroup=groupLayout.createSequentialGroup();
		for(int i=0;i<SIZE;i++){
			sequentialGroup.addGroup(createButtonFilePar(i, groupLayout));
		}
		return sequentialGroup;		
	}

	public ParallelGroup createButtonBoardParSeq(GroupLayout groupLayout){
		ParallelGroup parallelGroup=groupLayout.createParallelGroup();
		for(int i=0;i<SIZE;i++){
			parallelGroup.addGroup(createButtonFileSeq(i, groupLayout));
		}
		return parallelGroup;		
	}

}
